package com.zlx.guguanjia.mapper.provider;

import org.apache.ibatis.jdbc.SQL;
import org.springframework.util.StringUtils;

import java.util.Map;

/**
 * @Author 周罗校
 * @Description
 * @ClassName SysOfficeSqlProvider
 * @date 2020.10.31 11:43:16
 * 该版权归周罗校所有，最终解释权以官方为准
 */
public class SysOfficeSqlProvider {


    public String selectAll(Map<String,Object> map){
        return new SQL(){{
            SELECT("of.*, sa.`name` area_name ");
            FROM(" sys_office of ");
            LEFT_OUTER_JOIN(" sys_area sa ON of.area_id = sa.id ");
            WHERE(" of.del_flag = '0'");
            if (map.containsKey("oid")&&!StringUtils.isEmpty(map.get("oid"))){
                WHERE(" of.id = #{oid}");
            }else if (map.containsKey("name")&&!StringUtils.isEmpty(map.get("name"))){
                WHERE(" of.`name` LIKE CONCAT('%',#{name},'%')");
            }
        }
        }.toString();
    }
}
